/****

 * 2016.3.23
 * 全局js
 */

function openNewpage(go){
	mui.openWindow({
			id: go,
			url: go,
			show: {//出现动画设置
				aniShow: 'pop-in',
				duration: '300'
			},
			/*styles:{
				bottom:"50px",
				width:"100%"
			}*/
			waiting: {
				autoShow: false
			}
		});	
} 

/**
 * 搜索 指定栏目
 * @param {Object} tid
 */
function search(tid){
	var search =  plus.webview.create('search-1.html' , 'search-1' , {} , {tid : tid});
	search.addEventListener('loaded', function (){
		search.show('pop-in');
	})	
}

/**
 * 获取验证码
 * @param phone 手机号码
 * @return null
 */
function getverify(phone){
	
	plus.nativeUI.showWaiting('发送中...');
	
	$.ajax({
		
		url : 'http://app213.51edn.com/api/index.php/Home/Message/sendMessage/',
		
		type : 'post' ,
		
		data :{
			
			mobile : phone
			
		}, 
		
		dataType : 'json',
		
		success : function(data , status , xhr){ 
			
			plus.nativeUI.closeWaiting();
			
			console.log(JSON.stringify(data))
			
			if(data.status == '000'){
				
				plus.storage.setItem('verify' , data.code+'');
			
				toast('验证码发送成功');
				
				time_asc();
			
			}else{
				
				toast('验证码发送失败');
				
			}
			
		} , 
		
		error : function(e){
			
			console.log(JSON.stringify(e));
			
			toast('失去网络连接');
			
		}
		
	})
	
}



/**
 * 倒计时
 */
function time_asc(){
	
	$('.verification').attr('disabled' , true);
	
	var verfiy = '';
	
	var second = 60;
	
	verfiy = setInterval(function(){
		
		if(second <= 0){
			
			clearInterval(verfiy);
			
			reset_input(verfiy);
			
		}else{
			
			$('.verification').text(second -- + 's');
			
		}
		
	} , 1000);
	
}

/**
 * 重设状态
 */
function reset_input(verfiy){
	
	clearInterval(verfiy);
	
	$('.verification').removeAttr('disabled');
	
	$('.verification').text('重发验证');
	
}


/**
 * 检测用户是否存在
 * @param {String} phone
 */ 
function checkUser(phone , type){ 
	
	
	mui.post(apiRoot + '/Home/Member/checkUser/' , {'phone' : phone} ,
	
		function(data){
			
			if(data){
				
				if(type == 'forget_password'){
					
					$('.qr').removeAttr('disabled');//忘记密码
					
					getverify(phone);
					
				}else{
					
					$('.register').attr('disabled' , true);//注册
					
					toast('该用户已注册');
					
				}
				
			}else{
				
				if(type == 'forget_password'){
					
					$('.qr').attr('disabled' , true);//登录
					
					toast('找不到该用户');
					
				}else{
					
					$('.register').removeAttr('disabled');
					
					getverify(phone);

				}
			}
		}
	);
	
}


